Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Jan 9, 2025

improve performance for search code

Summary of the changes (Less than 80 chars)

简单描述你更改了什么, 不超过80个字符;如果有关联 Issue 请在下方填写相关编号

Description

fixes #5066

Regression?

  • Yes
  • No

[If yes, specify the version the behavior has regressed from]

[是否影响老版本]

Risk

  • High
  • Medium
  • Low

[Justify the selection above]

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Improve search code performance by using FrozenDictionary and HashSet for website options.

Enhancements:

  • Use FrozenDictionary for SourceCodes, Videos, and Links properties in WebsiteOptions.
  • Use HashSet for Themes property in WebsiteOptions.
  • Use ToLowerInvariant when retrieving source code type names.

@bb-auto bb-auto bot added the bug Something isn't working label Jan 9, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 9, 2025

Reviewer's Guide by Sourcery

This PR improves the performance of the search code by changing the data structures used to store website options from Dictionary to FrozenDictionary and List to HashSet.

Sequence diagram for improved code search process

sequenceDiagram
    participant Client
    participant CodeSnippetService
    participant FrozenDictionary

    Client->>CodeSnippetService: GetCodeAsync(codeFile)
    CodeSnippetService->>CodeSnippetService: Split codeFile
    CodeSnippetService->>FrozenDictionary: TryGetValue(key.ToLowerInvariant())
    Note over FrozenDictionary: Improved lookup performance
    FrozenDictionary-->>CodeSnippetService: value
    CodeSnippetService-->>Client: formatted code
Loading

Class diagram showing updated WebsiteOptions data structure changes

classDiagram
    class WebsiteOptions {
        +FrozenDictionary~string, string~ SourceCodes
        +FrozenDictionary~string, string~ Videos
        +FrozenDictionary~string, string~ Links
        +HashSet~ThemeOption~ Themes
        +WebsiteOptions()
    }
    note for WebsiteOptions "Changed from Dictionary to FrozenDictionary
Changed List to HashSet for better performance"

    class CodeSnippetService {
        -FrozenDictionary~string, string~ SourceCodes
        +GetCodeAsync(string codeFile) Task~string~
    }
    note for CodeSnippetService "Changed from Dictionary to FrozenDictionary"
Loading

File-Level Changes

Change Details Files
Replaced Dictionary with FrozenDictionary for storing source code, video, and link data.
  • Changed SourceCodes, Videos, and Links properties in WebsiteOptions from Dictionary<string, string?> to FrozenDictionary<string, string?>.
  • Updated the initialization of these properties to use ToFrozenDictionary.
  • Modified CodeSnippetService to use TryGetValue with a lowercase key on the SourceCodes dictionary.
src/BootstrapBlazor.Server/Data/WebsiteOptions.cs
src/BootstrapBlazor.Server/Services/CodeSnippetService.cs
Replaced List with HashSet for storing theme options.
  • Changed the Themes property in WebsiteOptions from List<ThemeOption> to HashSet<ThemeOption>.
  • Updated ThemeChooser component to use FirstOrDefault instead of Find to retrieve the current theme from the Themes collection.
src/BootstrapBlazor.Server/Data/WebsiteOptions.cs
src/BootstrapBlazor.Server/Components/Components/ThemeChooser.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#5066 Fix case sensitivity issue with URL routing for documentation pages The PR appears to be focused on performance improvements for search code and making collections frozen, but does not directly address the URL case sensitivity problem mentioned in the issue.
#5066 Ensure consistent page rendering regardless of URL case The changes do not modify URL routing or page rendering logic to handle case-insensitive URLs consistently.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot added this to the v9.2.0 milestone Jan 9, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ArgoZhang - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using HashSet.Contains() or TryGetValue() instead of FirstOrDefault() to take full advantage of HashSet's O(1) lookup performance when searching for themes
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang ArgoZhang enabled auto-merge (squash) January 9, 2025 05:48
@ArgoZhang ArgoZhang disabled auto-merge January 9, 2025 05:48
@ArgoZhang ArgoZhang enabled auto-merge (squash) January 9, 2025 05:48
@codecov
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (6113b85) to head (e88ce82).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #5075   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          631       631           
  Lines        27990     27990           
  Branches      4015      4015           
=========================================
  Hits         27990     27990           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ArgoZhang ArgoZhang merged commit 1e0338b into main Jan 9, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the doc-map branch January 9, 2025 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(docsite): url is not case sensitive, but *unix filesystem file path is

2 participants